package com.xyongfeng.foodManagement.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.xyongfeng.foodManagement.domain.group.AddGroup;
import com.xyongfeng.foodManagement.domain.group.NormalGroup;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import org.springframework.validation.annotation.Validated;

import javax.validation.constraints.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

/**
 * @TableName food_info
 */
@TableName(value = "t_food_info")
@Data
public class FoodInfo implements Serializable {
    /**
     * 食品编号
     */
    @TableId(type = IdType.AUTO)
    private Integer foodId;

    /**
     * 食品名称
     */
    @Length(min = 1, max = 20, message = "食品名称长度范围为1~20",groups = {NormalGroup.class})
    @NotBlank(message = "食品名称不能为空", groups = {AddGroup.class})
    private String foodName;

    /**
     * 食品类别号
     */
    private Integer foodCategoryId;

    /**
     * 食品单价
     */
    @Min(value = 0, message = "价格不能为负数", groups = {NormalGroup.class})
    @NotNull(message = "食品单价不能为空", groups = {AddGroup.class})
    private BigDecimal foodPrice;

    /**
     * 食品库存
     */
    @Min(value = 0, message = "库存不能为负数", groups = {NormalGroup.class})
    private Integer foodStock;

    /**
     * 食品保质期
     */
    @Pattern(regexp = "^\\d{4}-\\d{1,2}-\\d{1,2}$", message = "日期格式错误", groups = {NormalGroup.class})
    @NotBlank(message = "食品保质期不能为空", groups = {AddGroup.class})
    private String foodShelfLife;

    /**
     * 外键 食品种类
     */
    @TableField(exist = false)
    private FoodCategoryInfo foodCategoryInfo;

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        FoodInfo other = (FoodInfo) that;
        return (this.getFoodId() == null ? other.getFoodId() == null : this.getFoodId().equals(other.getFoodId()))
                && (this.getFoodName() == null ? other.getFoodName() == null : this.getFoodName().equals(other.getFoodName()))
                && (this.getFoodCategoryId() == null ? other.getFoodCategoryId() == null : this.getFoodCategoryId().equals(other.getFoodCategoryId()))
                && (this.getFoodPrice() == null ? other.getFoodPrice() == null : this.getFoodPrice().equals(other.getFoodPrice()))
                && (this.getFoodStock() == null ? other.getFoodStock() == null : this.getFoodStock().equals(other.getFoodStock()))
                && (this.getFoodShelfLife() == null ? other.getFoodShelfLife() == null : this.getFoodShelfLife().equals(other.getFoodShelfLife()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getFoodId() == null) ? 0 : getFoodId().hashCode());
        result = prime * result + ((getFoodName() == null) ? 0 : getFoodName().hashCode());
        result = prime * result + ((getFoodCategoryId() == null) ? 0 : getFoodCategoryId().hashCode());
        result = prime * result + ((getFoodPrice() == null) ? 0 : getFoodPrice().hashCode());
        result = prime * result + ((getFoodStock() == null) ? 0 : getFoodStock().hashCode());
        result = prime * result + ((getFoodShelfLife() == null) ? 0 : getFoodShelfLife().hashCode());
        return result;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", foodId=").append(foodId);
        sb.append(", foodName=").append(foodName);
        sb.append(", foodCategoryId=").append(foodCategoryId);
        sb.append(", foodPrice=").append(foodPrice);
        sb.append(", foodStock=").append(foodStock);
        sb.append(", foodShelfLife=").append(foodShelfLife);
        sb.append(", serialVersionUID=").append(serialVersionUID);
        sb.append("]");
        return sb.toString();
    }
}